import { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import reducers from '../reducers/index';
import { middleware } from '../../route/StartStack';
import { composeWithDevTools } from 'redux-devtools-extension';
import logger from 'redux-logger';
import { persistStore, persistReducer } from 'redux-persist'
import AsyncStorage from '@react-native-community/async-storage';

const persistConfig = {
    key: 'root',
    storage: AsyncStorage,
    blacklist: ['nav']
}

const persistedReducer = persistReducer(persistConfig, reducers)

const middlewares = [
    middleware,
    // logger,
    thunk
];

export default () => {
    const store = createStore(
        persistedReducer,
        composeWithDevTools(applyMiddleware(
            ...middlewares
        ))
    )
    let persistor = persistStore(store)
    return { store, persistor }
}